#!/bin/bash
cd `dirname $0`
source inc/common.bash

echo "This script will set up a lighttpd HTTP server configuration in $HTTP_DIR"
echo "lighttpd is the recommended way to deploy Geovision"

read -p 'Install a local lighttpd configuration? (y/n): ' CHOICE

if [ ! "$CHOICE" = "y" ]
then
	echo "Aborting."
	exit 1
fi

mkdir $HTTP_DIR
SOURCE_DIR=$(cd `dirname $0`/../src/geovision/; pwd)
sed -e "s#!HTTP_DIR!#$HTTP_DIR#g;s#!HTTP_PORT!#$HTTP_PORT#g;s#!SOURCE_DIR!#$SOURCE_DIR#g" < conf/lighttpd.conf.base > $HTTP_DIR/lighttpd.conf

cat <<EOF
Use these database settings in your settings.py

Host: $HOME/geovision-postgres/
Port: 4394
Database: geovision
Username: (leave blank)
Password: (leave blank)

You can easily connect to the database specified in your settings.py with the psql utility by running the run-psql script.

Your database is configured to accept connections only from the local user `whoami` using ident authentication.
See the PostgreSQL documentation for enabling access to other users in the $HOME/geovision-postgres/pg_hba.conf file.

Use the start-localpostgres and stop-localpostgres scripts to start/stop your database server.
Your database log is in $HOME/geovision-postgres/postgresql.log
EOF
